<?php
declare (strict_types = 1);

namespace app\adminapi\controller\system\organize;

use adminmatrix\annotation\auth\IsPermission;
use adminmatrix\server\app\server\JsonService;
use app\adminapi\logic\system\organize\CompanyLogic;
use think\exception\HttpException;
use think\Request;
use adminmatrix\server\app\adminMatrix;
use think\response\Json;

class CompanyController extends AdminMatrix
{
    public function lists(){
        return $this->dataLists();
    }


    public function save(Request $request , CompanyLogic $logic) : Json
    {
        try {
            $logic -> save($request);
            return JsonService::success('新增成功');
        } catch (HttpException $e)
        {
            return JsonService::fail($e->getMessage());
        }
    }


    public function update(Request $request , CompanyLogic $logic) : Json
    {
        try {
            $logic -> update( $request);
            return  JsonService::success('编辑成功');
        } catch ( HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }
    public function delete( int $id , Request $request , CompanyLogic $logic) : Json
    {
        try {

            $logic -> delete($id);
            return  JsonService::success('删除成功');
        } catch ( HttpException $e)
        {
            return  JsonService::fail($e->getMessage());
        }
    }

    #[IsPermission]
    public function getOrganizationList(Request $request) : Json
    {
        try {
            $lists = (new  CompanyLogic($this->app)) -> get($request);
            return  JsonService::success('' ,$lists);
        } catch (HttpException $exception)
        {
            return JsonService::fail($exception->getMessage());
        }
    }


}
